package com.estate.struts.actions;

import java.io.UnsupportedEncodingException;

import com.estate.business.PriceProjectService;
import com.estate.business.ProSuggestionService;
import com.estate.vo.impl.PriceProjectVo;
import com.estate.vo.impl.ProSuggestionVo;

public class StageInPriceAction extends EstateSupport {
	
	private String currentStage;
	private int regeditStage;
	private String method;
	private String regeditId;
	private PriceProjectService priceProjectService;
	private ProSuggestionService proSuggestionService;
	private String suggestion;
	
	public String execute() throws Exception{
		
		String page="";
		if("regedit".equals(method)){
			
			if("2".equals(currentStage)||"3".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(4);
				regeditStage=4;
				priceProjectService.updateVo(regeditVo);
				page = "selfVerify";
			} else if("4".equals(currentStage)||"5".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(6);
				regeditStage=6;
				priceProjectService.updateVo(regeditVo);
				page = "engineeringReview";
			} else if("6".equals(currentStage)||"7".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditStage=8;
				regeditVo.setStage(8);
				priceProjectService.updateVo(regeditVo);
				page = "tecReview";
			} else if("8".equals(currentStage)||"9".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditStage=10;
				regeditVo.setStage(10);
				priceProjectService.updateVo(regeditVo);
				page = "leaderReview";
			}else if("10".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(11);
				regeditStage=11;
				priceProjectService.updateVo(regeditVo);
				page = "projReport";
			} else if("11".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(12);
				regeditStage=12;
				priceProjectService.updateVo(regeditVo);
				page = "projUpload";
			}
			ProSuggestionVo suggestionVo=new ProSuggestionVo();
			suggestionVo.setProCatagory(1);
			suggestionVo.setProId(Integer.parseInt(regeditId));
			suggestionVo.setProStatus(regeditStage);
			suggestionVo.setSuggestion(suggestion);
			proSuggestionService.addSuggestion(suggestionVo);
		} else if("deny".equals(method)){
			if("2".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(3);
				regeditStage=3;
				priceProjectService.updateVo(regeditVo);
				page = "selfVerify";
			} else if("4".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(5);
				regeditStage=5;
				priceProjectService.updateVo(regeditVo);
				page = "engineeringReview";
			} else if("6".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(7);
				regeditStage=7;
				priceProjectService.updateVo(regeditVo);
				page = "tecReview";
			} else if("8".equals(currentStage)){
				PriceProjectVo regeditVo = (PriceProjectVo) priceProjectService
				.findByPK(Integer.parseInt(regeditId));
				regeditVo.setStage(9);
				regeditStage=9;
				priceProjectService.updateVo(regeditVo);
				page = "leaderReview";
			}
			ProSuggestionVo suggestionVo=new ProSuggestionVo();
			suggestionVo.setProCatagory(1);
			suggestionVo.setProId(Integer.parseInt(regeditId));
			suggestionVo.setProStatus(regeditStage);
			suggestionVo.setSuggestion(suggestion);
			proSuggestionService.addSuggestion(suggestionVo);
		}
		return page;
	}

	public void setCurrentStage(String currentStage) {
		this.currentStage = currentStage;
	}

	public String getCurrentStage() {
		return currentStage;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getMethod() {
		return method;
	}

	public void setRegeditId(String regeditId) {
		this.regeditId = regeditId;
	}

	public String getRegeditId() {
		return regeditId;
	}

	public void setPriceProjectService(PriceProjectService priceProjectService) {
		this.priceProjectService = priceProjectService;
	}

	public PriceProjectService getPriceProjectService() {
		return priceProjectService;
	}

	public void setSuggestion(String suggestion) {
		try {
			this.suggestion = new String(suggestion.getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	public String getSuggestion() {
		return suggestion;
	}

	public void setProSuggestionService(ProSuggestionService proSuggestionService) {
		this.proSuggestionService = proSuggestionService;
	}

	public ProSuggestionService getProSuggestionService() {
		return proSuggestionService;
	}

	public void setRegeditStage(int regeditStage) {
		this.regeditStage = regeditStage;
	}

	public int getRegeditStage() {
		return regeditStage;
	}

}
